﻿using UnityEngine;

public class HeroViewCreator : Singleton<HeroViewCreator>
{
    private string path = "Prefabs/HeroView/";

    public HeroView CreateHeroView(Hero heroData, GameObject viewSlot)
    {
        // 根据传入的 heroData 类型，得到类名
        string className = heroData.Name;
        string fullPath = path + className;

        HeroView prefab = Resources.Load<HeroView>(fullPath);
        //Debug.Log($"Trying to load prefab at: {fullPath}");
        if (prefab == null)
        {
            //Debug.LogError($"Prefab not found at path: Resources/{fullPath}");
            return null;
        }

        // 实例化预制体并挂到 viewSlot 下
        HeroView heroView = Instantiate(prefab, viewSlot.transform);

        // 调用 Setup，传入 heroData
        heroView.Setup(heroData);
        return heroView;
    }
}
